import {httpServer,wsServer,ossServer} from "@/config/server.js"
let systemInfo = uni.getSystemInfoSync();
let menuButtonInfo = {};
// 如果是小程序，获取右上角胶囊的尺寸信息，避免导航栏右侧内容与胶囊重叠(支付宝小程序非本API，尚未兼容)
// #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ
menuButtonInfo = uni.getMenuButtonBoundingClientRect();
// #endif
export default{
	
    data(){
        return {
			APP_NAME:'qys',//APP应用名称
			PAGE_TITLE:'qys',//页面标题
			
			//服务端相关ip / 域名
			baseURL:httpServer,
			wsURL:wsServer,
			ossURL:ossServer,
			
            //设置默认的分享参数
            share:{
                title:'',
                path:'/',
				href:'/',
                imageUrl:'',
                desc:'',
                content:'',
				summary:'',
				param:'',//页面传参
            },
			
			FULL_PATH:'',//当前页面全路径（带参）
			BASE_PATH:'',//当前页面初始路径（不带参）
			
			// #ifndef MP-WEIXIN
			NavBarHeight: 44 + systemInfo.statusBarHeight,
			// #endif
			// #ifdef MP-WEIXIN
			NavBarHeight: menuButtonInfo.bottom + menuButtonInfo.top - systemInfo.statusBarHeight,
			// #endif
			
			PAGE_HEIGHT:'',//页面可用高度
			PAGE_HEIGHT_PX:'',//页面可用高度,带px
			
			User_Info:{},
			
			PUBLIC_STYLE:{
				color:'#81c4d2',
				backgroundColor:'#81c4d2',
				fontSize:'28rpx'
			},
			
        }
    },
	methods: {
		//禁止滑动
		moveHandle: function() {},
		//初始化页面标题、路径等
		initPageShare(){
			//初始化页面可用高度
			this.PAGE_HEIGHT = uni.getWindowInfo().windowHeight
			this.PAGE_HEIGHT_PX = this.PAGE_HEIGHT+"px"
			
			// 获取栈实例
			var pages = getCurrentPages()
			//全局设置分享跳转参数
			let FULL_PATH = pages[pages.length - 1].$page.fullPath
			let BASE_PATH = '/'+pages[pages.length - 1].route
			this.FULL_PATH = FULL_PATH
			this.BASE_PATH = BASE_PATH
			if(FULL_PATH == `/${BASE_PATH}`){
				this.share.path += BASE_PATH
				this.share.href += BASE_PATH
			}else{
				this.share.path = FULL_PATH
				this.share.href = FULL_PATH
			}
			let currentRoute = pages[pages.length - 1].route+'.html'; // 获取当前页面路由
			let pageTitle = ''
			// #ifndef H5
			if(__wxConfig && __wxConfig.page){
				pageTitle=__wxConfig.page[currentRoute].window.navigationBarTitleText//获取当前页面标题
			}
			// #endif
			if(!this.share.title){
				this.$set(this.share,'title',pageTitle)
			}
		},
		//实现在微信、QQ浏览器下自动隐藏导航栏解决双标题问题，在H5手机浏览器下显示导航
		// #ifdef H5
		//判断是否在微信内置浏览器
		isWeiXinBrowser() {
			let ua = navigator.userAgent.toLowerCase()
			return ua.indexOf('micromessenger') != -1
		},
		//判断是否在QQ内置浏览器
		isQQBrowser() {
			var ua = navigator.userAgent.toLowerCase()
			if (ua.match(/QQ/i) == "qq") {
				return true
			} else {
				return false
			}
		},
		navTitle() {
			this.$nextTick(() => {
				let navTitleDom = document.getElementsByTagName('uni-page-head')
				if (navTitleDom.length) {
					navTitleDom[0].style.display = 'none'
				}
			})
		}
		// #endif
		
	},
	created(){
		// console.log('created')
	},
	onLoad(options){
		this.User_Info = uni.getStorageSync('user')
		// console.log('onLoad')
		this.initPageShare()
	},
	onReady(){
		// console.log('onReady')
	},
	onShow(){
		// console.log('onShow')
		this.SessionId = uni.getStorageSync('SessionId')
	},
	mounted() {
		// console.log('mounted')
		// #ifdef H5
		if (this.isWeiXinBrowser() || this.isQQBrowser()) {
			this.navTitle()
		}
		// #endif
	},
	//分享给朋友
	onShareAppMessage(res) {
	    return {
	        title:this.share.title,
	        path:this.share.path,
	        imageUrl:this.share.imageUrl,
	        desc:this.share.desc,
	        content:this.share.content,
	        success(res){
				console.log('分享给好友成功')
	            uni.showToast({
	                title:'分享给好友成功'
	            })
	        },
	        fail(res){
				console.log('分享给好友失败')
	            uni.showToast({
	                title:'分享给好友失败',
	                icon:'none'
	            })
	        }
	    }
	},
	//分享到朋友圈
	onShareTimeline(res) {
		return {
			title: this.share.title,
			href:this.share.href,
			query:'shareUser='+this.user_id,
			imageUrl:this.share.imageUrl,
			summary: this.share.summary,
			success(res){
				uni.showToast({
					title:'分享到朋友圈成功'
				})
			},
			fail(res){
				uni.showToast({
					title:'分享到朋友圈失败',
					icon:'none'
				})
			}
		}
	}
	
}